import {createBrowserRouter} from "react-router-dom";

import {MainLayout} from "../layouts/MainLayout";
import {ManageLayout} from "../layouts/ManageLayout";
import {QuestionLayout} from "../layouts/QuestionLayout";
import {Home} from '../pages/Home';
import {Login} from "../pages/Login";
import {Register} from "../pages/Register";
import {NotFound} from "../pages/NotFound";
import {List} from "../pages/manage/List";
import {Trash} from "../pages/manage/Trash";
import {Star} from "../pages/manage/Star";
// import {Edit} from "../pages/question/Edit";
// import {Stat} from "../pages/question/Stat";
import {lazy} from "react";

const Edit = lazy(() => import(/* webpackChunkName: "editPage" */ '../pages/question/Edit').then())
const Stat = lazy(() => import(/* webpackChunkName: "statPage" */ '../pages/question/Stat').then())

const router = createBrowserRouter([
    {
        path: '/',
        element: <MainLayout/>,
        children: [
            {
                path: '/',
                element: <Home/>,
            },
            {
                path: 'login',
                element: <Login/>,
            },
            {
                path: 'register',
                element: <Register/>,
            },
            {
                path: 'manage',
                element: <ManageLayout/>,
                children: [
                    {
                        path: 'list',
                        element: <List/>
                    },
                    {
                        path: 'star',
                        element: <Star/>
                    }, {
                        path: 'trash',
                        element: <Trash/>
                    },

                ]
            },

            {
                path: '*',
                element: <NotFound/>
            }
        ]
    },
    {
        path: 'question',
        element: <QuestionLayout/>,
        children: [
            {
                path: 'edit/:id',
                element: <Edit/>
            },
            {
                path: 'stat/:id',
                element: <Stat/>
            },
        ]
    },
])

export default router

// ---------------- 分割线 ------------------
export const HOME_PATHNAME = '/'
export const LOGIN_PATHNAME = '/login'
export const REGISTER_PATHNAME = '/register'
export const MANAGE_INDEX_PATHNAME = '/manage/list'


export function isLoginOrRegister(pathname: string) {
    return [LOGIN_PATHNAME, REGISTER_PATHNAME].includes(pathname);
}

export function isNoNeedUserInfo(pathname: string) {
    return ([HOME_PATHNAME, LOGIN_PATHNAME, REGISTER_PATHNAME].includes(pathname))
}
